package com.dong.boot.service.emp;

import com.dong.boot.mapper.*;
import com.dong.boot.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    EmployeeMapper employeeMapper;
    @Autowired
    PoliticsstatusMapper politicsstatusMapper;
    @Autowired
    NationMapper nationMapper;
    @Autowired
    JobLevelMapper jobLevelMapper;
    @Autowired
    DepartmentMapper departmentMapper;
    @Autowired
    PositionMapper positionMapper;

    public RespPageBean getAllEmployee(Integer pageNo, Integer pageSize, Employee employee, Date[] beginEndScope) {
        if (pageNo != null){
            pageNo = (pageNo -1) * pageSize;
        }
        RespPageBean bean = new RespPageBean();
        bean.setData(employeeMapper.getEmployeeByPage(pageNo,pageSize,employee,beginEndScope));
        bean.setTotal(employeeMapper.getTotal(employee,beginEndScope));
        return bean;
    }

    public Boolean addEmployee(Employee employee) {
        employeeMapper.insert(employee);
        return true;
    }

    public List<Politicsstatus> getAllPoliticsStatus() {
        return politicsstatusMapper.getAllPoliticsstatus();
    }

    public List<Nation> getAllnations() {
        return nationMapper.getAllNations();
    }

    public List<JobLevel> getAllJobLevel() {
        return jobLevelMapper.getAllJobLevels();
    }

    public List<Position> getAllPositions() {
        return positionMapper.getAllPositions();
    }

    public List<Department> getAllDepartments() {
        return departmentMapper.getAllDepartmentsByParentId(-1);
    }

    public boolean updateEmployee(Employee employee) {
        employeeMapper.updateByPrimaryKeySelective(employee);
        return true;
    }

    public boolean deleteEmp(Integer id) {
        employeeMapper.deleteByPrimaryKey(id);
        return  true;
    }

    public List<Department> getAllDepartmentWithOutChildren() {
        return departmentMapper.getAllDepartmentsWithOutChildren();
    }

    public void batchAddEmployee(List<Employee> list) {
        employeeMapper.addEmps(list);
    }
}
